import { create } from 'zustand'
import { createJSONStorage, persist } from 'zustand/middleware'
import globalConfig from '@/core/framework/config/globalConfig'
import { LayoutTabsState } from '@/ui/antd/types/model/dto/LayoutTabsState'

const useLayoutStore = create(
	persist<LayoutTabsState>(
		(setState, getState) => {
			return {
				tabs: [],
				refresh: false,
			} as LayoutTabsState
		},
		{
			name: `${globalConfig.storageKeyPrefix}.app.layout.tabs`,
			storage: createJSONStorage(() => sessionStorage),
		},
	),
)

export default useLayoutStore
